<?php
/******************************************************************
 *
 *  Programmer: Nick Wertzberger
 *       Email: wertnick@gmail.com
 *
 *  An example element in the Model section
 *  The following class is supposed to be the table for putting up 
 *  a post...
 *
 ******************************************************************/

class Post extends Table
{
    protected $table_name = 'posts';
    protected $table_options = array(
        'comment' => 'Article Repository',
        'character_set' => 'utf8',
        'collate' => 'utf8_unicode_ci',
        'type'    => 'innodb',
    );
    protected $table_definition = array (
        'id' => array(
            'type' => 'integer',
            'unsigned' => 1,
            'notnull' => 1,
            'default' => 0,
        ),
        'title' => array(
            'type' => 'text',
            'length' => 256,
        ),
        'post' => array(
            'type' => 'clob',
            'length' => 4096 
        ),
        'date' => array(
            'type' => 'timestamp',
        ),
    );

    // used to declare keys and whatnot
    protected $table_constraints = array(
        'key1' => array( 'primary' => true,
            'fields' => array (
                'id' => array (),
            ),
        ),
    );

    // declare indices
    protected $table_indices = array();

    
    // returns an array of results up to MAX posts
    public function & get_posts($max=100, $offset=0)
    {
        $rval = array();

        $res =& $this->db_conn->query("SELECT * FROM posts ORDER BY id DESC LIMIT $offset, $max");
        if (!PEAR::isError($res))
        {
            while ( $x = $res->fetchRow(MDB2_FETCHMODE_OBJECT) )
            {
                $rval[] = $x; 
            }
        }

        return $rval;
    }
}
